package org.example.travel_web.controller.admin;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.example.travel_web.dto.PageResult;
import org.example.travel_web.dto.sysUser.PageReq;
import org.example.travel_web.dto.sysUser.PageResp;
import org.example.travel_web.dto.sysUser.SysUserReq;
import org.example.travel_web.entity.SysUserET;
import org.example.travel_web.service.SysUserService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/sysUser")
@Tag(name = "管理员用户管理")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;


    @GetMapping
    @Operation(summary = "分页查询用户")
    public PageResult<PageResp> page(@Valid PageReq req) {
        return sysUserService.pageResult(req);
    }


    @GetMapping("/{id}")
    @Operation(summary = "查询用户详情")
    @Parameter(name = "id", description = "用户id", required = true, in = ParameterIn.PATH)
    public SysUserET get(@PathVariable("id") Long id) {
        return sysUserService.get(id);
    }

    @PostMapping
    @Operation(summary = "新增用户")
    public void add(@Valid SysUserReq req) {
        sysUserService.add(req);
    }

    @PutMapping()
    @Operation(summary = "更新用户")
    public void update(@Valid SysUserReq req) {
        sysUserService.updateSysUser(req);
    }

    @DeleteMapping()
    @Operation(summary = "删除用户")
    @Parameter(name = "ids", description = "用户id数组", required = true, in = ParameterIn.QUERY)
    public void delete(Long[] ids) {
        sysUserService.delete(ids);
    }
}
